﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

  

using System.Security.Cryptography;
using System.Text;
 
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Linq;
using NBHF.BusinessService;
using NBHF.Models;
using NBHF.Common.CommonEnum;

public partial class LoginNew : System.Web.UI.Page
{
     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            Session.RemoveAll();

        }
    }

    /// <summary>
    /// 验证用户名和密码
    /// </summary>
    /// <returns></returns>
    private bool VaildDate()
    {
        string strUserID = txtAccount.Text.Trim();
        string strUserPass = txtPassword.Text.Trim();

        if (string.IsNullOrEmpty(strUserID))
        {
            txtAccount.Focus();
            lblErrorMsg.Text = "用户名不能为空。";
            return false;
        }

        if (string.IsNullOrEmpty(strUserPass))
        {
            txtPassword.Focus();
            lblErrorMsg.Text = "密码不能为空。";
            return false;
        }

        return true;
    } 
    /// <summary>
    /// 登录
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        bool blnVaildDate = VaildDate();
        if (!blnVaildDate)
        {
            return;
        }
        else
        {
            AppUserLoginResultModel resultobj = UserService.AppUserLogin(this.txtAccount.Text.Trim(), this.txtPassword.Text.Trim());

            if (resultobj.code != "0")
            {
                this.lblErrorMsg.Text = resultobj.message;
            }
            else
            {
                Session[SessionType.Userid] = resultobj.userid;
                Session[SessionType.Clientname] = resultobj.cusname;
                Session[SessionType.Cusref] = resultobj.cusref;
                Session[SessionType.Phone] = resultobj.phone;

                if (resultobj.usertp != AppUserType.CompanyUser)
                {
                    this.lblErrorMsg.Text = "非企业用户不得使用！";
                    return;
                }
                else
                {
                    Response.Redirect("Frame/Home.aspx");
                }
            }



        }


    }

   
}
 